package com.example.quickinjectdemo;

import com.android.bind.QuickBind;
import com.android.bind.annotation.BindLayout;
import com.android.bind.annotation.BindView;
import com.android.bind.annotation.OnItemClick;
import com.android.bind.annotation.OnItemLongClick;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

@BindLayout(R.layout.activity_list)
public class ListActivity extends Activity {
	@BindView(R.id.listview)
	private ListView mListView;
	private BaseListAdapter mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		QuickBind.bind(this);
		mAdapter = new BaseListAdapter();
		mListView.setAdapter(mAdapter);
	}

	@OnItemClick(R.id.listview)
	private void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long arg3) {
		Log.e("ListActivity", "onItemClick 测试成功" + position);
	}

	@OnItemLongClick(R.id.listview)
	private boolean onItemLongClick(AdapterView<?> arg0, View arg1,
			int position, long arg3) {
		Log.e("ListActivity", "onItemLongClick 测试成功" + position);
		return true;
	}

	class BaseListAdapter extends BaseAdapter {

		@Override
		public int getCount() {
			return 10;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				convertView = LayoutInflater.from(ListActivity.this).inflate(
						R.layout.item_list, null, false);
				holder = new ViewHolder(convertView);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			if (position % 2 == 0) {
				holder.image.setBackgroundColor(ListActivity.this
						.getResources().getColor(android.R.color.darker_gray));
			} else {
				holder.image.setBackgroundColor(ListActivity.this
						.getResources().getColor(
								android.R.color.holo_blue_bright));
			}
			holder.text.setText(position + "位置排名");
			return convertView;
		}

		class ViewHolder {
			@BindView(R.id.text)
			TextView text;
			@BindView(R.id.image)
			ImageView image;

			public ViewHolder(View view) {
				QuickBind.bind(this, view);
			}

		}

	}
}
